package com.laborer.controller;

import com.laborer.entity.User;
import com.laborer.model.result.Result;
import com.laborer.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @Auther: Wangym
 * @Date: 2021/6/18 22:12
 * @Description:
 */
@Controller
@RequestMapping("/changePassword")
public class ChangePasswordController {

    @Autowired
    private IUserService userService;
    private String PREFIX = "changePassword";
    @RequestMapping("")
    public String changePassword(String userName, Model model){
        model.addAttribute("userName",userName);
        return PREFIX + "/changePassword";
    }

    @RequestMapping("/updatePassword")
    @ResponseBody
    public Result updatePassword(User user){
        Result result=new Result();
        boolean updateLogin = userService.updatePassword(user);
        if(updateLogin){
            result.success(null, 10 ,1);
            return result;
        }
        result.error("修改密码失败!");
        return result;
    }
}
